//
//  QSSystemToolsHelper.m
//  wisdompark_ios_teacher
//
//  Created by SJ on 2018/5/27.
//  Copyright © 2018年 QS. All rights reserved.
//

#import "QSSystemToolsHelper.h"
#import <MessageUI/MessageUI.h>
@interface QSSystemToolsHelper ()<MFMessageComposeViewControllerDelegate>

@property (nonatomic, strong) UIViewController *messageParentVC;

@end

@implementation QSSystemToolsHelper

+ (instancetype)sharedHelper {
    static id sharedInstance = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });
    
    return sharedInstance;
}


#pragma mark - ***************** Message
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self.messageParentVC dismissViewControllerAnimated:YES completion:nil];
    switch (result) {
        case MessageComposeResultSent:
            //信息传送成功
            
            break;
        case MessageComposeResultFailed:
            //信息传送失败
            
            break;
        case MessageComposeResultCancelled:
            //信息被用户取消传送
            
            break;
        default:
            break;
    }
}

- (void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body inParentController:(UIViewController *)parentVC
{
    self.messageParentVC = parentVC;
    if( [MFMessageComposeViewController canSendText]) {
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = phones;
        controller.body = body;
        controller.messageComposeDelegate = self;
        [parentVC presentViewController:controller animated:YES completion:nil];
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                        message:@"该设备不支持短信功能"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}

@end
